/*
 * #%L
 * ServerDAO
 * %%
 * Copyright (C) 2011 Ractoc.com
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package com.ractoc.opengamefinder.dao;

import java.io.Serializable;
import javax.persistence.CascadeType;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.AccessType;

/**
 * Object representation of a database record containing all the data related to
 * a player account.
 * 
 * @author ractoc
 * @version 0.1
 */
@Entity
@AccessType("property")
@Table(name = "ACCOUNTS")
public class AccountDAO implements Serializable {

    private static final long serialVersionUID = 1L;
    private Integer id;
    private Integer version;
    private String name;
    private String password;
    private AvatarDAO avatar;

    /**
     * Default constructor.
     */
    public AccountDAO() {
    }

    /**
     * Get the version of the record, used for optimistic locking.
     * @return The version of the record.
     */
    @Version
    @Column(name = "VERSION")
    public Integer getVersion() {
        return version;
    }

    /**
     * Set the version of the record, used for optimistic locking.
     * @param versionParam The version of the record.
     */
    public void setVersion(final Integer versionParam) {
        this.version = versionParam;
    }

    /**
     * Set the id of the player account.
     * @param idParam The id of the player account.
     */
    public void setId(final Integer idParam) {
        this.id = idParam;
    }

    /**
     * Get the id of the player account.
     * @return The id of the player account.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ACCOUNT_ID")
    public Integer getId() {
        return id;
    }

    /**
     * Set the name of the player.
     * @param nameParam The name of the player.
     */
    public void setName(final String nameParam) {
        this.name = nameParam;
    }

    /**
     * Get the name of the player.
     * @return The name of the player.
     */
    @Column(name = "NAME", length = 15, unique = true, nullable = false)
    public String getName() {
        return name;
    }

    /**
     * Set the password of the player.
     * @param passwordParam The password of the player.
     */
    public void setPassword(final String passwordParam) {
        this.password = passwordParam;
    }

    /**
     * Get the password of the player.
     * @return The password of the player.
     */
    @Column(name = "PASSWORD", length = 15, nullable = false)
    public String getPassword() {
        return password;
    }

    @OneToOne(cascade = CascadeType.ALL, fetch= FetchType.EAGER, optional=true)
    public AvatarDAO getAvatar() {
        return avatar;
    }

    public void setAvatar(AvatarDAO avatar) {
        this.avatar = avatar;
    }
}
